<?php

class Mobiles extends MY_Admin
{
	// Protected or private properties
	protected $_template;
	
	// Constructor
	public function __construct()
	{
		parent::__construct();
			
		// Check if the logged user is an administrator
		//$this->access_library->check_access();

		// Load needed models, libraries, helpers and language files 
		$this->load->module_model('admin', 'mobiles_model', 'mobiles');
		
		$this->load->module_language('admin', 'general');
		$this->load->module_language('admin', 'mobiles');
	}

	// Public methods
	
	public function index()
	{
		$lang_working = load_language_working();
		$data['mobiles'] = $this->mobiles->get_all_mobile();

		$this->_template['page']	= 'mobiles/list';

		$this->system_library->load($this->_template['page'], $data, TRUE);
		//$this->load->library('image_lib');
	}

	public function create_link()
	{
		$this->form_validation->set_rules('name', 'lang:form_name', 'required|max_length[50]|xss_clean');
		$this->form_validation->set_rules('url', 'lang:form_url', 'required|xss_clean');
		$this->form_validation->set_rules('target', 'lang:form_target', 'required|xss_clean');
		$this->form_validation->set_rules('description', 'lang:form_description', 'required|max_length[100]|xss_clean');
		$this->form_validation->set_rules('visible', 'lang:form_visible', 'required|xss_clean');
		if ($this->form_validation->run() == TRUE)
		{
			$this->links->create_link();
			
			$this->session->set_flashdata('message', lang('successfully_created'));

			redirect('admin/mobiles', 'refresh');
		}
		$this->_template['page']	= 'mobiles/create_link';		
		$this->system_library->load($this->_template['page'], null, TRUE);
	}
	public function create()
	{
		$lang_working = load_language_working();
		$this->form_validation->set_rules('name', 'lang:form_name', 'required|max_length[50]|xss_clean');
		$this->form_validation->set_rules('description', 'lang:form_description', 'max_length[100]|xss_clean');

		$this->form_validation->set_error_delimiters('', '<br />');		
		// Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class:
		if ($this->form_validation->run() == TRUE)
		{
			$this->mobiles->create_brand();		
			$this->session->set_flashdata('message', lang('successfully_created'));
			redirect('admin/mobiles', 'refresh');
		}	
		else
		{
			$this->_template['page']	= 'brands/create';
				
			$this->system_library->load($this->_template['page'], null, TRUE);
		}
	}

	public function edit($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
		$this->form_validation->set_rules('name', 'lang:form_name', 'required|max_length[50]|xss_clean');
		$this->form_validation->set_rules('description', 'lang:form_description', 'max_length[100]|xss_clean');
		$this->form_validation->set_error_delimiters('', '<br />');
		$data['brand'] = $this->brands->get_brand($id);
	
		if ($this->form_validation->run() == TRUE)
		{
			$this->mobiles->edit_brand($id);
			//echo 'a'; exit();
			$this->session->set_flashdata('message', lang('successfully_edited'));
			redirect('admin/mobiles', 'refresh');
		}
		else
		{
			$this->_template['page']	= 'mobiles/edit';
			$this->system_library->load($this->_template['page'], $data, TRUE);
		
		}
	}
	
	public function delete($id)
	{
		$this->mobiles->delete_mobile($id);
		$this->session->set_flashdata('message', lang('successfully_deleted'));
		redirect('admin/mobiles', 'refresh');
	}
	
	public function enable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->mobiles->change_status_mobile($id,1);
		redirect('admin/mobiles', 'refresh');
		
	}
	public function disable($id = null)
	{
		if ($id == null)
		{
			$id = $this->input->post('id');
		}
			
		$this->mobiles->change_status_mobile($id,0);
		redirect('admin/mobiles', 'refresh');
	}
}

/* End of file links.php */
/* Location: ./application/modules/admin/controllers/links.php */